package com.java2401.springbootv2.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.util.UrlPathHelper;

@Configuration(proxyBeanMethods = false)
public class MyConfig implements WebMvcConfigurer {
    //自定义filter
    @Bean
    public HiddenHttpMethodFilter hiddenHttpMethodFilter(){
        HiddenHttpMethodFilter methodFilter = new HiddenHttpMethodFilter();
        methodFilter.setMethodParam("_m");
        return methodFilter;
    }
	// 开启矩阵变量功能
    public WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void configurePathMatch(PathMatchConfigurer configurer) {
                UrlPathHelper urlPathHelper = new UrlPathHelper();
                urlPathHelper.setRemoveSemicolonContent(false);
                configurer.setUrlPathHelper(urlPathHelper);
            }
        };
    }

    // 第二种写法
   // @Override
   // public void configurePathMatch(PathMatchConfigurer configurer) {
       // UrlPathHelper urlPathHelper = new UrlPathHelper();
        // 默认是移除;后面的内容，我们改为false（不移除），让矩阵变量生效
      //  urlPathHelper.setRemoveSemicolonContent(false);
      //  configurer.setUrlPathHelper(urlPathHelper);
  //  }
}